package com.oritsh.dicom.utils.adaptor;

import com.google.gson.*;
import org.dcm4che.data.*;

import java.lang.reflect.Type;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: zarra
 * Date: 14-2-5
 * Time: 下午4:03
 * Copyright Shanghai Orient Rain Information Technology Co.,Ltd.
 */
public class AttributesGsonAdaptor implements JsonSerializer<Attributes>,JsonDeserializer<Attributes> {

    @Override
    public Attributes deserialize(JsonElement json, Type typeOfT,
                                  JsonDeserializationContext context) throws JsonParseException {
        Type dataType = JsonAdaptorHelper.gsonDataType();
        Map<String, Object> map = context.deserialize(json, dataType);
        return JsonAdaptorHelper.mapToAttributes(map);
    }

    @Override
    public JsonElement serialize(Attributes src, Type typeOfSrc,
                                 JsonSerializationContext context) {

        Type dataType = JsonAdaptorHelper.gsonDataType();
        Map<String, Object> map = JsonAdaptorHelper.attributesToMap(src);
        return context.serialize(map, dataType);
    }

}

